{% extends 'blog/base.html' %}

<!-- 内容 -->
{% block content %}


    <div class="lyear-wrapper">
  <section class="mt-5 pb-5">
    <div class="container">

      <div class="row">
        <!-- 文章列表 -->
        <div class="col-xl-8">




         {% if page_obj.object_list.count > 0 %}
          {% for blogpost in page_obj.object_list %}
          <article class="lyear-arc">
            <div class="arc-header">
              <h2 class="arc-title"><a href="article/{{ blogpost.id }}">{{ blogpost.title }}</a></h2>
              <ul class="arc-meta">
                <li><i class="mdi mdi-calendar"></i> {{ blogpost.pubTime }}</li>
                <li><i class="mdi mdi-tag-text-outline">
                </i> {% for tag in blogpost.tags.all %}<a href="{% url 'index' %}?tag={{ tag.id }}">{{ tag.tag }}</a>&nbsp{% endfor %}</li>
                <!--<li><i class="mdi mdi-comment-multiple-outline"></i> <a href="#">3 评论</a></li>-->
                <li><i class="mdi mdi-heart-outline"></i> <a href="#">{{ blogpost.viewsCount }} 喜欢</a></li>
              </ul>
            </div>

            <div class="arc-synopsis">
              <p>{{ blogpost.summary }}</p>
            </div>
          </article>
         {% endfor %}


          <!-- 分页 -->
          <div class="row">
            <div class="col-lg-12">
              <ul class="pagination">
               {% if page_obj.has_previous %}
                <li class="page-item"><a class="page-link" href="?page={{ page_obj.previous_page_number }}"><i class="mdi mdi-chevron-left"></i></a></li>
               {% endif %}
              <!--
                <li class="page-item active"><a class="page-link" href="#">1</a></li>
                <li class="page-item"><a class="page-link" href="#">2</a></li>
                <li class="page-item"><a class="page-link" href="#">3</a></li>
                <li class="page-item"><a class="page-link" href="#">4</a></li>
                <li class="page-item"><a class="page-link" href="#">5</a></li>
                         -->

                {% for page_no in page_obj.paginator.page_range %}
                    {% if page_no >= start_page and page_no <= end_page %}
                        {% if page_no == page_obj.number %}
                            <li class="page-item active"><a class="page-link" href="#">{{ page_no }}</a></li>
                        {% else %}
                            <li class="page-item"><a class="page-link" href="?page={{ page_no }}{% if tag_id %}&tag={{ tag_id }}{% endif %}{% if year %}&year={{ year }}{% endif %}{% if search %}&search={{ search }}{% endif %}">{{ page_no }}</a></li>
                        {% endif %}
                    {% endif %}
                {% endfor %}


              {% if page_obj.has_next %}
                <li class="page-item"><a class="page-link" href="?page={{ page_obj.next_page_number }}{% if tag_id %}&tag={{ tag_id }}{% endif %}{% if year %}&year={{ year }}{% endif %}{% if search %}&search={{ search }}{% endif %}"><i class="mdi mdi-chevron-right"></i></a></li>
              {% endif %}

              <p>总页数: {{ page_obj.paginator.num_pages}}</p>
              </ul>
            </div>
          </div>
            {% else %}
            <p> 没有找到文章 </p>
            {% endif %}
          <!-- 分页 end -->

      </div>
        <!-- 内容 end -->

        <!-- 侧边栏 -->
        <div class="col-xl-4">
          <div class="lyear-sidebar">
            <!-- 热门文章 -->
            <aside class="widget widget-hot-posts">
              <div class="widget-title">热门文章</div>
              <ul>
                  {% for post in hot_posts %}
                <li>
                  <a href="{% url 'post_detail' id=post.id %}">{{ post.title }}</a> <span>{{ post.pubTime }}</span>
                </li>
                  {% endfor %}
              </ul>
            </aside>

            <!-- 归档 -->
            <aside class="widget">
              <div class="widget-title">归档</div>
              <ul>
                  {% for post in post_grouped_by_year %}
                      <li><a href="{% url 'index' %}?year={{ post.year|date:'Y' }}" >{% if year == post.year|date:'Y' %}<b>{{ post.year|date:'Y' }} 年 </b>{% else %}{{ post.year|date:'Y' }} 年{% endif %}</a> ({{ post.publication_count }})</li>
                  {% endfor %}
              </ul>
            </aside>

            <!-- 标签 -->
            <aside class="widget widget-tag-cloud">
              <div class="widget-title">标签 </div>
              <div class="tag-cloud">
                  {% for tag in tags %}
                <a href="{% url 'index' %}?tag={{ tag.id }}" {% if tag_id == tag.id %}class="badge badge-primary"{% else %}class="badge badge-light"{% endif %}>{{ tag.tag }}</a>
                  {% endfor %}
              </div>
            </aside>
          </div>
        </div>
        <!-- 侧边栏 end -->
      </div>

    </div>
    <!-- end container -->
  </section>
</div>


{% endblock %}
<!-- 内容 end -->